package com.elephant.bean.selfEditor;

import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceEditor;
import org.springframework.core.io.ResourceLoader;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

import java.beans.PropertyEditorSupport;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.FileSystemNotFoundException;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * @author 林
 * @create 2025-05-22 11:08
 */
//自定义的数据解析类
public class AddressEditor extends PropertyEditorSupport {
	/**
	 * Create a new PathEditor, using the default ResourceEditor underneath.
	 */
	public AddressEditor() {
	}

	//做自定义的数据解析，把他设置进setValue就好了
	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		String[] split = text.split("_");
		Address address = new Address();
		address.setProvince(split[0]);
		address.setCity(split[1]);
		address.setTown(split[2]);
		setValue(address);
	}

	/**
	 * This implementation returns {@code null} to indicate that
	 * there is no appropriate text representation.
	 */
	@Override
	@Nullable
	public String getAsText() {
		return null;
	}
}
